#ifndef __XIOSTREAM_H__
#define __XIOSTREAM_H__

#include "xdata.h"
#include <list>
#include <thread>
#include <mutex>
#include <condition_variable>


class XIOStream
{
public:
    void start();
    void wait();
    void stop();
    void setNext(std::shared_ptr<XIOStream> next);
    void push(std::shared_ptr<XData> data);
    void setMemPool(std::shared_ptr<std::pmr::memory_resource> pool);
    std::shared_ptr<XData> pop();
    virtual ~XIOStream();
protected:
    virtual void handle() = 0;
    bool isExit_ = false;
    long long dataBytes_ = 0;
    std::shared_ptr<std::pmr::memory_resource> memPool_;
    std::shared_ptr<XIOStream> next_;
private:
    std::mutex mutex_;
    std::list<std::shared_ptr<XData>> datas_;
    std::condition_variable notEmpty_;
    std::condition_variable notFull_;
    std::thread th_;
    size_t maxDatasSize = 200;
};

#endif
